package com.naml.a_thread;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/26 16:27
 * @desc 演示通过实现Runnable接口建线程
 */
@SuppressWarnings("all")
public class Runnable02 {
    public static void main(String[] args) {
        Thread thread = new Thread(new Dog());
        thread.start();

        for (int i = 0; i < 10; i++) {
            try {
                System.out.println(Thread.currentThread().getName() + ":" + i);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}


@SuppressWarnings("all")
class Dog implements Runnable {

    @Override
    public void run() {
        int i = 0;
        while (true){
            try {
                System.out.println(Thread.currentThread().getName()+":汪汪汪～"+(++i));
                Thread.sleep(1000);
                if (i == 80){
                    break;
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
